package appx.craft.droid.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Storage {
	
	public static void verifyImagePath() throws IOException {
		try{
			
			File dir = new File(Constance.IMAGE_DIR);

			if (!dir.exists()) {
				dir.mkdirs();
			}

			dir = null;

		}catch (Exception e) {
			e.printStackTrace();
		}
				
	}
	
	public static void veirfyLogPath() throws IOException {
		File dir = new File(Constance.LOG_DIR);
		if (!dir.exists()) {
			dir.mkdirs();
		}
		dir = null;
	}

	public static File verifyLogFile() throws IOException {
		File logFile = new File(Constance.LOG_DIR + "/Log_"
				+ new SimpleDateFormat("yyyy_MM_dd").format(new Date())
				+ ".html");
		FileOutputStream fos = null;

		Storage.veirfyLogPath();

		if (!logFile.exists()) {
			logFile.createNewFile();
			
			fos = new FileOutputStream(logFile);
			
			String str = "<TABLE style=\"width:100%;border=1px\" cellpadding=2 cellspacing=2 border=1><TR>"
				+ "<TD style=\"width:30%\"><B>Date n Time</B></TD>"
				+ "<TD style=\"width:20%\"><B>Title</B></TD>" 
				+ "<TD style=\"width:50%\"><B>Description</B></TD></TR>";
			
			fos.write(str.getBytes());
		}

		if (fos != null){
			fos.close();
		}
		
		fos = null;
		
		return logFile;
	}
	
	
	
	
}

